package com.mk.legoscans2.data;

import java.util.HashMap;
import java.util.Map;

import com.mk.legoscans2.LegoScans3Application;

public class FavoritesRepositoryFactory {
	
	private Map<String, FavoritesRepository> _repositories;
	
	public FavoritesRepositoryFactory(){
		_repositories = new HashMap<String, FavoritesRepository>();
	}
	
	public FavoritesRepository getRepository(String selectedAccount){

		if(_repositories.containsKey(selectedAccount))
			return _repositories.get(selectedAccount);

		if(selectedAccount.contains("@"))
		{
			FavoritesRepository favoritesRepository = new CachingFavoritesRepository(new ApiFavoritesRepository(selectedAccount, LegoScans3Application.ApiDomain, LegoScans3Application.ApiPort));
			_repositories.put(selectedAccount, favoritesRepository);
			return favoritesRepository;
		}
		
		FavoritesRepository favoritesRepository = new LocalFavoritesRepository(LegoScans3Application.ApplicationPreferences);
		_repositories.put(selectedAccount, favoritesRepository);
		return favoritesRepository;
	}
}
